"use strict";
const code = require("../errorCode.js");

module.exports = (options) => {
  return async (ctx, next) => {
    const {body}=ctx.request;
    for (let i=0;i<options.body2jsonList.length;i++){
      if (body.hasOwnProperty(options.body2jsonList[i])){
        if (typeof body[options.body2jsonList[i]] === 'string'){
          ctx.request.body[options.body2jsonList[i]] = JSON.parse(body[options.body2jsonList[i]])
        }
      }
    }
    await next();
  };
};
